import request from "@/utils/request";

const baseUrl = "systemUser/";

/**
 * 获取所有菜单
 * @param pagination
 * @param keyword
 * @returns {AxiosInstance}
 */
export function page(pagination, keyword) {
    return new request({
        url: `${baseUrl}list`,
        method: "GET",
        params: {...pagination, ...keyword}
    })
}

/**
 * 修改单个用户
 * @returns {AxiosInstance}
 * @param data
 */
export function updateUser(data) {
    return new request({
        url: `${baseUrl}`,
        method: "PUT",
        data: data
    })
}

/**
 * 增加单个角色
 * @param data
 * @returns {AxiosInstance}
 */
export function addUser(data) {
    return new request({
        url: `${baseUrl}`,
        method: "POST",
        data: data
    })
}

/**
 * 修改用户角色
 */
export function updateUserRole(userId, roleIds) {
    return new request({
        url: `${baseUrl}update/role`,
        method: "PUT",
        data: {userId, roleIds}
    })
}

/**
 * 重置用户密码
 * @returns {AxiosInstance}
 * @param data
 */
export function initUserPassword(id) {
    return new request({
        url: `${baseUrl}password`,
        method: "PUT",
        params: {id}
    })
}

/**
 * 是否启用用户
 */
export function enableUser(id, status) {
    return new request({
        url: `${baseUrl}enable`,
        method: "PUT",
        data: {id, status}
    })
}


/**
 * 删除单个用户
 * @returns {AxiosInstance}
 * @param id
 */
export function deleteUser(id) {
    return new request({
        url: `${baseUrl}?id=${id}`,
        method: "DELETE",
    })
}

/**
 * 强制用户下线
 */
export function offline(id) {
    return new request({
        url: `${baseUrl}offline`,
        method: "PUT",
        params: {id}
    })
}